import request from '@/utils/request'

const userApi = {
  Login: '/auth/login',
  Logout: '/auth/logout',
  ForgePassword: '/auth/forge-password',
  Register: '/auth/register',
  twoStepCode: '/auth/2step-code',
  SendSms: '/account/sms',
  getSmsEmail: '/account/email',
  SendSmsErr: '/account/sms_err',
  // get my info
  UserInfo: '/sysUser/info',
  // UserMenu: '/user/nav'
  UserMenu: '/currentUser/menuList',
  giteeLogin: '/auth/gitee/login',
  giteeaccessToken: '/auth/gitAccessToken',
  getGiteeUserInfoAndLogin: '/auth/getGiteeUserInfoAndLogin',
  gitHubLogin: '/auth/getGitHubCode',
  register: '/auth/register',
  updatepassword: '/auth/updatepassword'
}

/**
 * login func
 * parameter: {
 *     username: '',
 *     password: '',
 *     remember_me: true,
 *     captcha: '12345'
 * }
 * @param parameter
 * @returns {*}
 */
export function login(parameter) {
  return request({
    url: userApi.Login,
    method: 'post',
    data: parameter
  })
}

export function getSmsCaptcha(parameter) {
  return request({
    url: userApi.SendSms,
    method: 'post',
    data: parameter
  })
}
export function logout() {
  return request({
    url: userApi.Logout,
    method: 'get'
  })
}
export function getSmsEmail(parameter) {
  return request({
    url: userApi.getSmsEmail,
    method: 'post',
    params: parameter
  })
}

export function getInfo() {
  return request({
    url: userApi.UserInfo,
    method: 'get',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    }
  })
}

export function getCurrentUserNav() {
  return request({
    url: userApi.UserMenu,
    method: 'get'
  })
}

export function updatePwd(data) {
  return request({
    url: userApi.updatepassword,
    method: 'post',
    data
  })
}

/**
 * get user 2step code open?
 * @param parameter {*}
 */
export function get2step(parameter) {
  return request({
    url: userApi.twoStepCode,
    method: 'post',
    data: parameter
  })
}
/**
 * 授权登录
 * @returns
 */
export function giteeLogin() {
  return request({
    url: userApi.giteeLogin,
    method: 'get'
  })
}
/**
 * 获取gitee的accessToken
 * @param {*} code
 * @returns
 */
export function giteeaccessToken(url, code) {
  return request({
    // url: userApi.giteeaccessToken,
    url: url,
    method: 'post',
    params: {
      code
    }
  })
}

/**
 * 获得个人信息及登录
 */
export function getGiteeUserInfoAndLogin(url, accessToken) {
  return request({
    // url: userApi.getGiteeUserInfoAndLogin,
    url: url,
    method: 'get',
    params: {
      accessToken
    }
  })
}

/**
 * 授权登录
 * @returns
 */
export function gitHubLogin() {
  return request({
    url: userApi.gitHubLogin,
    method: 'get'
  })
}

export function register(params) {
  return request({
    url: userApi.register,
    method: 'post',
    data: params
  })
}
